<template>
  <div class="variable-context">
    <el-row>
      <el-col :lg="12" :sm="24">
        <el-popconfirm title="确定要删除此属性全部数据?">
          <template #reference>
            <el-button type="danger">
              删除属性
            </el-button>
          </template>
        </el-popconfirm>
      </el-col>
    </el-row>

    <json-schema-form
        v-model="mvRef"
        :formProps="{layoutColumn: 1}"
        :schema="schema"
    >
      <template #default="{ formData, formRefFn }">
        <el-row>
          <el-col :lg="24" :sm="24">
            <el-button type="primary" @click="saveData(formData.value)">
              保存数据
            </el-button>
          </el-col>
        </el-row>
        <pre style="background-color: #eee;">{{ JSON.stringify(formData.value, null, 4) }}</pre>
      </template>
    </json-schema-form>
  </div>
</template>
<script lang="ts" setup>
import JsonSchemaForm from '@lljj/vue3-form-element';
import {ref, reactive} from "vue";

const props = defineProps({editData: {type: null, default: null}});
const editData = props.editData;
const modelValue = reactive({...editData});
const mvRef = ref(modelValue)
const schema = {
  "type": "object",
  "additionalProperties": false,
  "definitions": {
    "entityConfig": {
      "description": "实体类描述，可以使用 ${#currentSillyEntityMap} 获取当前的对象属性值，${#parentSillyEntityMap}获取父对象属性值，${#preSillyEntity}获取上个对象",
      "properties": {
        "fields": {
          "description": "属性配置",
          "title": "属性配置",
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "fieldName": {
                "description": "属性名称，不配置默认跟Key相同",
                "title": "属性名称",
                "type": "string"
              },
              "desc": {
                "description": "属性的描述信息",
                "title": "描述信息",
                "type": "string"
              },
              "required": {
                "description": "是否必填项，默认必填",
                "title": "必填项",
                "default": "${}"
              },
              "requiredMessage": {
                "description": "必填项提示内容",
                "title": "必填项提示内容",
                "type": "string"
              },
              "checkEl": {
                "description": "自定义的数据校验 true为通过，当配置此项时，required配置失效",
                "title": "自定义的数据校验",
                "type": "string",
                "default": "${}"
              },
              "relationField": {
                "description": "关联父对象字段，父字段名称，当配置此属性时，不支持SPEL操作",
                "title": "关联父对象字段",
                "default": "id"
              },
              "defaultValue": {
                "description": "默认值",
                "title": "默认值",
                "default": "${}"
              },
              "finalValue": {
                "description": "最终值【relationField: true 时 此值不可为空】",
                "title": "最终值",
                "default": "${}"
              },
              "entityConfig": {
                "$ref": "#/definitions/entityConfig"
              }
            },
            "required": [
              "desc"
            ]
          }
        },
        "entityClass": {
          "description": "实体类全限定名",
          "title": "实体类全限定名",
          "type": "string"
        },
        "arrayData": {
          "description": "数据是否为数组格式，默认为true",
          "title": "数组格式",
          "type": "boolean",
          "default": false
        },
        "needDelete": {
          "description": "是否需要删除之前且此次未保存的数据，默认为false",
          "title": "删除之前数据",
          "type": "boolean",
          "default": true
        },
        "needShow": {
          "description": "是否需要展示在root内，默认为false",
          "title": "展示在root内",
          "type": "boolean",
          "default": true
        },
        "ignoreFields": {
          "description": "忽略的保存参数名称，若不配置则默认忽略[createDate, createUserId, updateDate, updateUserId]",
          "title": "忽略的保存参数名称",
          "type": "array",
          "items": {
            "title": "忽略的参数名称",
            "type": "string"
          }
        }
      },
      "additionalProperties": false,
      "required": [
        "entityClass",
        "fields"
      ]
    }
  },
  "properties": {
    "requiredEl": {
      "type": "string",
      "default": "${}",
      "description": "支持SPEL表达式，'1'为需要，'0'为不需要, 表达式需要以 “${”开头，“}”结尾",
      "title": "必填表达式"
    },
    "required": {
      "type": "boolean",
      "default": false,
      "description": "是否必须项",
      "title": "是否必须项"
    },
    "checkEl": {
      "type": "string",
      "default": "${}",
      "description": "自定义的数据校验（基于root对象校验）true为通过",
      "title": "自定义的数据校验"
    },
    "variableName": {
      "type": "string",
      "description": "变量字段（若不设置默认为此对象KEY）",
      "title": "变量字段"
    },
    "desc": {
      "type": "string",
      "default": "",
      "description": "描述字段",
      "title": "描述字段"
    },
    "remarks": {
      "type": "string",
      "default": "",
      "description": "备注描述字段",
      "title": "备注描述字段"
    },
    "requiredMessage": {
      "type": "string",
      "default": "",
      "description": "必填提示内容",
      "title": "必填提示内容"
    },
    "updatePropertyHandleValue": {
      "type": "boolean",
      "default": false,
      "description": "是否更新此字段信息到处理器上下文中，默认true",
      "title": "是否更新此字段信息到处理器上下文中"
    },
    "belong": {
      "type": "string",
      "default": "master",
      "description": "此变量归属对象，但都会存到variable中",
      "title": "归属对象",
      "enum": [
        "master",
        "node",
        "variable"
      ]
    },
    "variableType": {
      "type": "string",
      "default": "string",
      "description": "变量类型，基础（string,list）其余的都是根据业务衍生出来的，通过实现SillyVariableConvertor接口可拓展[支持SPEL]",
      "title": "变量类型",
      "enum": [
        "entity",
        "newProcess",
        "newProcesses",
        "string",
        "number",
        "date",
        "dateTime",
        "list",
        "temp",
        "label",
        "labels"
      ]
    },
    "engineVariableType": {
      "type": "string",
      "default": "",
      "description": "工作流变量类型，基础（string,list）其余的都是根据业务衍生出来的，通过实现SillyVariableConvertor接口可拓展[支持SPEL]",
      "title": "工作流变量类型",
      "enum": [
        "string",
        "list"
      ]
    },
    "params": {
      "type": "object",
      "default": {},
      "description": "变量内部参数 可在SillyVariableConvertor中获取",
      "title": "变量内部参数",
      "properties": {
        "category": {
          "type": "string",
          "description": "配合【variableType=newProcess或newProcesses】使用，表示默认触发新流程的业务分类",
          "title": "新流程的业务分类",
        },
        "defaultSaveMap": {
          "type": "object",
          "description": "配合【variableType=newProcess或newProcesses】使用，表示默认参数Map",
          "title": "默认参数Map",
          "additionalProperties": true
        },
        "finalSaveMap": {
          "type": "object",
          "description": "配合【variableType=newProcess或newProcesses】使用，表示最终参数Map",
          "title": "最终参数Map",
          "additionalProperties": true
        },
        "pattern": {
          "type": "string",
          "description": "配合【variableType=formatDate】使用，表示字符格式化配置如yyyy-MM-dd",
          "title": "字符格式化",
        },
        "showPattern": {
          "type": "string",
          "description": "配合【variableType=formatDate】使用，表示显示字符格式化配置如yyyy-MM-dd",
          "title": "显示字符格式化",
        },
        "entityConfig": {
          "$ref": "#/definitions/entityConfig"
        }
      }
    },
    "userGroupVariableName": {
      "type": "string",
      "default": "",
      "description": "分组变量名称",
      "title": "分组变量名称",
    },
    "defaultText": {
      "type": "string",
      "default": "${}",
      "description": "变量的默认值，支持spel表达式，表达式需要以 “${”开头，“}”结尾",
      "title": "变量的默认值",
    },
    "finalText": {
      "type": "string",
      "default": "${}",
      "description": "变量的最终值，支持spel表达式，表达式需要以 “${”开头，“}”结尾",
      "title": "变量的最终值",
      "examples": [
        "${#master}",
        "${#masterId}",
        "${#currentDate}",
        "${#currentUserId}"
      ]
    },
    "saveHandleNames": {
      "type": "array",
      "default": [],
      "uniqueItems": true,
      "description": "变量保存处置器名称，可配置多个按配置的顺序执行，保存处置器可通过实现SillyVariableSaveHandle接口拓展",
      "title": "保存处置器名称",
      "items": {
        "type": "string",
        "enum": [
          "default",
          "dataJoin",
          "overwrite",
          "save",
          "skip",
          "deleteOtherTask"
        ]
      }
    }
  },
  "required": [
    "desc"
  ]
};

const saveData = (val: any) => {
  Object.assign(editData, val);
}
</script>
<script lang="ts">
export default {
  name: "SillyCategoryVariableSchemaForm"
}
</script>

<style scoped>
.variable-context {
  padding-left: 50px;
}
</style>